//index.js
const config = require('../../config.js')
const http = require('../../http.js')
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      page:1,
      pageSize:20,
      search:'',
      catId:'',
      showModal: false, 
  },
     
  buttontap(e) {
    this.setData({
      showModal: true
    })
  },

  hideModal(e){
    this.setData({
      showModal: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCivilContent();
    this.getDir();
  },

  getCivilContent: function () {
    var that = this
    http.request(
      config.getCivilList,
      'get', {
        page : that.data.page,
        pageSize :that.data.pageSize,
        search :that.data.search,
        catId:that.data.catId
      },
      function (res) {
        if (res.rows!= null) {
          that.setData({
              listData: res.rows,
          })
        }
      },
      function (err) {
        wx.showToast({
            title: "数据加载失败！",
            icon: 'none',
          })
      } )
  },

  getDir: function () {
    var that = this
    http.request(
      config.getCivilCategory,
      'get', null,
      function (res) {
        if (res.rows!= null) {
          that.setData({
            treeData: res.rows[0],
           })
        }
      },
      function (err) {
        wx.showToast({
            title: "数据加载失败！",
            icon: 'none',
          })
      } )
  },

  /**
   * 监听搜索
   */
  listenersearchInput:function(e){
    this.setData({
      keyword:e.detail.value
   })      
  },

  searchBar: function (e) {
    var  keyword=this.data.keyword;
    if(keyword!=undefined && keyword !=""){
      wx.navigateTo({
        url: "../civilsearch/civilsearch?keyword=" + keyword,
      })
    }else{
      wx.showToast({
        title: "请输入关键字",
        icon: 'none',
      })
    }
  },

  tapItem: function(res){
    this.setData({
      catId:res.detail.itemid,
     })
    this.getCivilContent();
    this.hideModal();
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})